<?php

$__FILEPATH__ = dirname(__FILE__)."/";
require_once($__FILEPATH__."func_common.php");
require_once($__FILEPATH__."class_def.php");
require_once($__FILEPATH__."conf/info.php");

header("Content-Type: text/html; charset=UTF-8");

$mysqli = GetMysqliInstance();

$PageArray = array();
$PageArray["algo_classlist"] = array();

$result = $mysqli->query("select * from classlist where type = 'algorithm'", MYSQLI_USE_RESULT);
if ($result)
{
	while($row = $result->fetch_array(MYSQLI_ASSOC))
	{
		$ClassItem = new ClassListItem();
		$ClassItem->id = intval($row["id"]);
		$ClassItem->type = $row["type"];
		$ClassItem->name = $row["name"];
		$ClassItem->cnt  = intval($row["cnt"]);
		$ClassItem->intra = $row["intra"];
		$PageArray["algo_classlist"][] = $ClassItem;
	}
	$result->close();
}

$ClassItem = new ClassListItem();
$ClassItem->id = 0;
$ClassItem->type = "algorithm";
$ClassItem->name = "未分类";
$ClassItem->cnt = 0;
$ClassItem->intra = "";

$result = $mysqli->query("select count(bid) as cnt from bclinklist where cid = 0", MYSQLI_USE_RESULT);
if ($result)
{
	if ($row = $result->fetch_array(MYSQLI_ASSOC))
		$ClassItem->cnt  = intval($row["cnt"]);
	$result->close();
}

$PageArray["algo_classlist"][] = $ClassItem;


$PageArray["new_bloglist"] = array();
$result = $mysqli->query("select id, title, user,in_time from bloglist order by in_time desc limit 0, $blog_news_list_max_cnt", MYSQLI_USE_RESULT);
if ($result)
{
	while($row = $result->fetch_array(MYSQLI_ASSOC))
	{
		$BlogItem = new BlogListItem();
		$BlogItem->id = intval($row["id"]);
		$BlogItem->title = $row["title"];
		$BlogItem->user = $row["user"];
		$BlogItem->in_time  = $row["in_time"];
		$PageArray["new_bloglist"][] = $BlogItem;
	}
	$result->close();
}

$monthstr = GetSysTime();
$monthstr = substr($monthstr, 0, 7);

$PageArray["date_bloglist"] = array();

$i = 0;
do
{
	$year = substr($monthstr, 0, 4);
	$month = substr($monthstr, 5, 2);
	$result = $mysqli->query("select count(id) from bloglist where in_time like \"$monthstr%\"", MYSQLI_USE_RESULT);
	if ($result)
	{
		if(($row = $result->fetch_array(MYSQLI_NUM)) && intval($row[0]) > 0)
		{
			++$i;
			$DateItem = new DateListItem();
			$DateItem->date = $year."-".$month;
			$DateItem->datestr = sprintf("%04d%s%02d%s", $year, "年", $month, "月");
			$DateItem->cnt = $row[0];
			$PageArray["date_bloglist"][] = $DateItem;
		}
		$result->close();
	}
	$monthstr = AddDateByMonth($monthstr, -1);

}while($i < $month_list_max_cnt && intval($year) >= 2014 && intval($month) > 1);

$mysqli->close();

?>